home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / program / lxtw109.zip / LXT.CB < prev    next >
Text File  |  1996-08-03  |  44KB  |  1,262 lines

  1. /*****************************************************************************/
  2. /*
  3.     LXT.CB - BRIEF MACRO FUNCTIONS FOR
  4.  
  5.         LFTN (TM) LISP FUNCTION TREE NAVIGATOR
  6.  
  7.     Copyright (C) Juergen Mueller (J.M.) 1992-1996
  8.     All rights reserved.
  9.  
  10.     You are expressly prohibited from selling this software in any form,
  11.     distributing it with another product, or removing this notice.
  12.  
  13.     Limited permission is given to registered LXT users to modify this
  14.     file for their own personal use only. This file may not be used for any
  15.     purpose other than in conjunction with the LXT software package.
  16.  
  17.     THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
  18.     EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, THE
  19.     IMPLIED WARRANTIES OF MERCHANTIBILITY OR FITNESS FOR A PARTICULAR
  20.     PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
  21.     PROGRAM AND DOCUMENTATION IS WITH YOU.
  22.  
  23.     written by: Juergen Mueller, Aldingerstrasse 22, D-70806 Kornwestheim,
  24.                 GERMANY
  25.  
  26.     FILE       : LXT.CB
  27.     REVISION   : 27-Apr-1996
  28.                  18:31:27
  29.  */
  30. /*****************************************************************************/
  31.  
  32. #include "dialog.h"     /* include file from original BRIEF DIALOG menus */
  33.  
  34.  
  35. /*****************************************************************************/
  36. /* defines */
  37. /*****************************************************************************/
  38. #define TMPFILE         "LXTFILE.TMP"
  39.  
  40. #define LFTNPROG        "lftn"          /* or "lftn4os2" for OS/2 */
  41.                                         /* or "lftn32" for Windows NT / Windows 95 */
  42.  
  43. #ifdef __OS2__
  44. #define upper(x)        (x)
  45. #endif
  46.  
  47. /*****************************************************************************/
  48. /**** USER macro function prototypes ****/
  49. /*****************************************************************************/
  50. void    lft(void);
  51. void    lftfind(void);
  52. void    lftmenu(void);
  53. void    lftbase(void);
  54. void    lftfilemenu(void);
  55. void    lftxrefmenu(void);
  56. void    lftxrefmenuagain(void);
  57. void    lftdefmenu(void);
  58.  
  59. /*****************************************************************************/
  60. /**** INTERNAL macro function prototypes ****/
  61. /*****************************************************************************/
  62. void    _init(void);            /* initialisation function, called on entry */
  63. void    _lxtmenu_exit(void);
  64. void    _exec_error(int retval, string format, string par1, string par2);
  65. string  _extract_item(void);
  66. void    _lxt(string, string);
  67. void    _lxt_search(string, string, string, int, int);
  68. void    _lxt_edit_file(void);
  69. void    _lxt_locate(void);
  70. void    _lxt_buffers(void);
  71. void    _lxtmenu(string, string);
  72. int     _lft_action(int, ...);
  73. void    _lxtfilemenu(string, string);
  74. int     _lxt_fileaction(int, ...);
  75. void    _lxtxrefmenu(string, string, int);
  76. int     _lxt_xrefaction(int, ...);
  77. void    _lxtdefmenu(string, string);
  78. int     _lxt_defaction(int, ...);
  79. void    _lxt_insert_sorted(string, int, int);
  80.  
  81.  
  82. /*****************************************************************************/
  83. /**** global variables ****/
  84. /*****************************************************************************/
  85. string  lft_base;               /* data base name for lft */
  86.  
  87. string  lxt_loc;                /* resulting file with item location */
  88.  
  89. string  lxt_item;               /* item to search for */
  90. int     lxt_id;                 /* item id */
  91.  
  92. string  lxt_file;               /* target file name */
  93. int     lxt_line;               /* target line, used by registered macro */
  94.  
  95. string  lft_loc;                /* resulting file for menu */
  96. int     lft_menuwidth;          /* horizontal lft menu width */
  97.  
  98. string  lft_files;              /* resulting file for filemenu */
  99. int     lft_filemenuwidth;      /* horizontal lft filemenu width */
  100.  
  101. string  lft_xref;                
  102. string  lft_xref_item;
  103. int     lft_xrefmenuwidth;       
  104.  
  105. string  lft_deffile;
  106. string  lft_def_item;
  107. int     lft_defmenuwidth;
  108.  
  109.  
  110. /*****************************************************************************/
  111. /**** macro package initialization function ****/
  112. /*****************************************************************************/
  113. void _init(void)
  114. {
  115.   /* init LFT base with environment */
  116.   lft_base = trim(ltrim(inq_environment("LFTNBASE")));
  117.  
  118.   lxt_loc = "lxt.loc";          /* intermediate file for search results */
  119.   lft_loc = "lft.loc";          /* used for function menu */
  120.   lft_files = "lft_file.loc";   /* used for function file menu */
  121.   lft_xref = "lft_xref.loc";
  122.   lft_xref_item = "";
  123.   lft_deffile = "lft_def.loc";
  124.   lft_def_item = "";
  125.  
  126.   /* register macro to delete temporary files on exit from BRIEF */
  127.   register_macro(5, "_lxtmenu_exit");
  128. }
  129.  
  130. /*****************************************************************************/
  131. /* registered macro to perform actions on exit of BRIEF or */
  132. /* if changes of database names have happened */
  133. /*****************************************************************************/
  134. void _lxtmenu_exit(void)
  135. {
  136.   if (exist(lft_loc))
  137.     del(lft_loc);
  138.  
  139.   if (exist(lft_files))
  140.     del(lft_files);
  141.  
  142.   if (exist(lft_xref))
  143.     del(lft_xref);
  144.  
  145.   if (exist(lft_deffile))
  146.     del(lft_deffile);
  147. }
  148.  
  149. /*****************************************************************************/
  150. /**** user callable macros ****/
  151. /*****************************************************************************/
  152. void lft(void)                  /* find function */
  153. {
  154.   _lxt(LFTNPROG, lft_base);     /* do function retrieval */
  155. }
  156.  
  157. void lftfind(void)              /* find user defined item */
  158. {
  159.   string item;
  160.  
  161.   get_parm(NULL, item, "LFT function name: ", 50);
  162.   item = compress(trim(ltrim(item)));
  163.  
  164.   if (strlen(item))
  165.     _lxt_search(LFTNPROG, lft_base, item, 0, 0);
  166. }
  167.  
  168. void lftmenu(void)              /* build function menu */
  169. {
  170.   _lxtmenu(LFTNPROG, lft_base);
  171. }
  172.  
  173. void lftbase(void)              /* set LFT database name */
  174. {
  175.   get_parm(NULL, lft_base, "LFT database name: ", 50, lft_base);
  176.   lft_base = trim(ltrim(lft_base));
  177.   _lxtmenu_exit();              /* delete menu files */
  178. }
  179.  
  180. void lftfilemenu(void)          /* build LFT file menu */
  181. {
  182.   _lxtfilemenu(LFTNPROG, lft_base);
  183. }
  184.  
  185. void lftxrefmenu(void)          /* build function cross reference menu */
  186. {
  187.   _lxtxrefmenu(LFTNPROG, lft_base, 1);
  188. }
  189.  
  190. void lftxrefmenuagain(void)     /* rebuild menu for previous item */
  191. {
  192.   _lxtxrefmenu(LFTNPROG, lft_base, 0);
  193. }
  194.  
  195. void lftdefmenu(void)
  196. {
  197.   _lxtdefmenu(LFTNPROG, lft_base);
  198. }
  199.  
  200. /*****************************************************************************/
  201. /**** internal macro execution functions ****/
  202. /*****************************************************************************/
  203.  
  204. /*****************************************************************************/
  205. /* */
  206. /*****************************************************************************/
  207. void _exec_error(int retval, string format, string par1, string par2)
  208. {
  209.   if (retval >= 100)
  210.     message(format, par1, par2);
  211.   else 
  212.     message("Command execution error (%d)", retval);
  213. }
  214.  
  215. /*****************************************************************************/
  216. /* read search item from current buffer */
  217. /*****************************************************************************/
  218. string _extract_item(void)
  219. {
  220.   int    move_flag, markval, marklen;
  221.   int    start_line, start_col, end_line, end_col;
  222.   string itemname, act_char, tmp_char, fchar, nchar;
  223.  
  224.   fchar = "[$_a-zA-Z]";         /* first character of an identifier */
  225.   nchar = "[$_a-zA-Z0-9\\-]";   /* not first character of an identifier */
  226.  
  227.   if (!(markval = inq_marked(start_line, start_col, end_line, end_col)))
  228.   {                             /* nothing marked, use cursor position */
  229.     if (!search_string(nchar, read(1)))
  230.     {
  231.       message("Invalid cursor position");
  232.       return "";
  233.     }
  234.  
  235.     save_position();            /* save the current position */
  236.     act_char = read(1);         /* read current character */
  237.  
  238.     whi